﻿using System;
using System.Collections.Generic;
using System.Text;

using Torch.WL.Entity.CleanChina;
using System.Data.SqlClient;
using System.Data;

namespace Torch.WL.DataAccess.CleanChina
{
    public class TbRewardAccess
    {
        public TbRewardAccess()
        {

        }


        private TbRewardEntity DataRowToModel(DataRow row)
        {
            TbRewardEntity model = new TbRewardEntity();
            if (row != null)
            {
                if (row["rewardId"] != null && row["rewardId"].ToString() != "")
                {
                    model.rewardId = int.Parse(row["rewardId"].ToString());
                }
                if (row["rewardName"] != null)
                {
                    model.rewardName = row["rewardName"].ToString();
                }
                if (row["createTime"] != null && row["createTime"].ToString() != "")
                {
                    model.createTime = DateTime.Parse(row["createTime"].ToString());
                }
            }
            return model;
        }

        private DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select rewardId,rewardName,createTime ");
            strSql.Append(" FROM Tb_Reward ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        public List<TbRewardEntity> GetRewardList()
        {
            DataSet ds = GetList("" );
            return DataTableToList(ds.Tables[0]);
        }

        private List<TbRewardEntity> DataTableToList(DataTable dt)
        {
            List<TbRewardEntity> modelList = new List<TbRewardEntity>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                TbRewardEntity model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = DataRowToModel(dt.Rows[n]);
                    if (model != null)
                    {
                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }



    }
}
